#include "sg4c.h"

sg_font_t font;


int Counter=0;

void setup(){
    font = sgCreateFont("Arial", 36);
}

void draw(){

    sgNoStroke();
    sgFill( sgGray(0xff) );
    sgRect(0, 0, sgWidth(), sgHeight());



    char textbuf[128];
    sprintf(textbuf, "Hello World! %d", Counter++);

    sgFont(font);
    sgFill( sgGray(0) );
    sgText(textbuf, 10, font.height*2 );


}


//events
void mouseMoved(){
    //Mouse moved
}

void mousePressed(){
    //A mouse button is pressed
}

void mouseReleased(){
    //A mouse button is released
}

void mouseClicked(){
    //A mouse button is pressed and released
    fputs("Redraw\n", stderr);
    sgRedraw();
}

void mouseDragged(){
    //The mouse moves when being pressed
}

void mouseEntered(){
    //The mouse pointer enters the display frame
    fputs("Redraw\n", stderr);
    sgRedraw();
}

void mouseExited(){
    //The mouse pointer leaves the display frame
}

void keyReleased(){
    //A key is released
}

void keyPressed(){
    //A key is pressed
}

void keyTyped(){
    //A key is pressed and then released
}

int main(){
    sg_config_t config;
    sgInitConfig( &config );

    config.screen.width = 400;  //set the horizontal resolution of the frame
    config.screen.height = 200; //set the vertical resolution of the frame
    config.framerate = 0;       //set backend driven mode

    //config.smooth = 1; // uncomment this line to enable smoothing

    //------------------------------------------------------------------
    //DO NOT MODIFY CODE BELOW

    //setup callbacks
    config.setup = setup;
    config.draw = draw;

    config.mousePressed = mousePressed;
    config.mouseReleased = mouseReleased;
    config.mouseMoved = mouseMoved;
    config.mouseEntered = mouseEntered;
    config.mouseExited = mouseExited;
    config.mouseClicked = mouseClicked;
    config.mouseDragged = mouseDragged;

    config.keyReleased = keyReleased;
    config.keyPressed = keyPressed;
    config.keyTyped = keyTyped;

    //initilize the system
    sgSetup(&config);

    //run forever
    return sgRunForever();
}
